/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Training;

import au.com.bytecode.opencsv.CSVReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 *
 * @author fabio
 */
public class SpamLabels {

    private HashMap labels;
    private String labelFilePath;

    public SpamLabels() {
        labels = new HashMap<String, Integer>();
        labelFilePath = "SpamDataSet/SPAMTrain.label";
    }

    public void readLabels() throws FileNotFoundException, IOException {
        FileInputStream labelFile = new FileInputStream(labelFilePath);
        CSVReader reader = new CSVReader(new InputStreamReader(labelFile));
        for (String[] row : reader.readAll()) {
            labels.put(row[1], Integer.parseInt(row[0]));
        }
//        Set<String> fileNames = labels.keySet();
//        for (String str : fileNames) {
//            System.out.println(str + " " + labels.get(str));
//        }
    }

    public int getSpamLabel(String mailFileName) {
        int label = -1;
        if (labels.containsKey(mailFileName)) {
            label = (Integer) labels.get(mailFileName);
        }
        return label;
    }
}
